export let initState = {
    shopList: [],
    checkAll: false,
    isshow: true
}

export const reducer = (state, action) => {
    switch (action.type) {
        case "changeShopList":
            // action.arr.forEach(item => item.checked = true)
            return {
                ...state,
                shopList: [...action.arr]
                // shopList: [...action.arr]
            }
        case "changeCheckAll":
            /* state.checkAll = action.obj
            state.shopList.forEach(item => {
                item.checked = state.checkAll
            })
            return {
                ...state,
                checkAll:state.checkAll,
                shopList:[...state.shopList]
            } */
            return {
                ...state,
                // shopList: state.shopList.map(item=>{
                //     return {
                //         ...item,
                //         checked:action.obj
                //     }
                // }),
                checkAll:action.obj,
            }
        case "changeShow":
            return {
                ...state,
                isshow: action.obj
            }

        default:
            return state
    }
}

export let actions = {
    changeShopList: (arr) => ({ type: "changeShopList", arr }),
    changeCheckAll: (obj) => ({ type: "changeCheckAll", obj }),
    changeShow: (obj) => ({ type: "changeShow", obj }),
}

export let getShopList = state => state.shopList
export let getShow = state => state.isshow
export let getCheckAll = state => state.checkAll




